package com.imooc.order.message;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 接收Mq消息
 * @author jack
 * @date 2019年1月16日
 */
@Slf4j
@Component
public class MqReceiver {

	//1、不会自动创建mq, @RabbitListener(queues="myQueue")
	//2、会自动创建mq, @RabbitListener(queuesToDeclare = @Queue("myQueue2"))
	//3、queue和exchange绑定
	@RabbitListener(bindings = @QueueBinding(exchange = @Exchange("myExchange"), value = @Queue("myQueue2")))
	public void process(String message) {
		log.info("MqReceiver: {}", message);
	}
	
	@RabbitListener(bindings = @QueueBinding(
				exchange = @Exchange("order"),
				key = "computer",
				value = @Queue("computerOrder")
			))
	public void processComputer(String message) {
		log.info("computer Receiver: {}", message);
	}
	
	@RabbitListener(bindings = @QueueBinding(
			exchange = @Exchange("order"),
			key = "fruit",
			value = @Queue("fruitOrder")
		))
	public void processFruit(String message) {
		log.info("fruit Receiver: {}", message);
	}
	
}
